package com.example.core.config;

import org.python.google.common.net.HttpHeaders;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CrossConfig implements WebMvcConfigurer {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**").
                        allowedOrigins("*"). //域名
                        allowedMethods("*"). //post、get
                        allowedHeaders("*"). //
                        allowCredentials(true). //cookie
                        exposedHeaders(HttpHeaders.SET_COOKIE).maxAge(3600L); //3600秒内缓存结果
            }
        };
    }

}
